import { _decorator, Component, Node, CircleCollider2D, IPhysics2DContact, v3 } from 'cc';
import { GlobalConfig } from '../../Init/Config/GlobalConfig';
import { GlobalEnum } from '../../Init/Config/GlobalEnum';
import { EventTypes } from '../../Init/Managers/EventTypes';
import { Bullet2D } from './Bullet2D';
const { ccclass, property } = _decorator;

/**穿透子弹 击中敌人之后不会消失 */
@ccclass('ThroughBullet2D')
export class ThroughBullet2D extends Bullet2D {

    // #region -------------事件-----------
    protected onBeginContact(selfCollider: CircleCollider2D, otherCollider: CircleCollider2D, contact: IPhysics2DContact | null) {
        if (this._isFinish) return;

        switch (otherCollider.group) {
            //墙壁.障碍物.敌方建筑
            case 1 << 4:
            case 1 << 7:
            case 1 << 8:
                this._isFinish = true;
                //击中效果
                this._tmpP.x = this.node.position.x * GlobalConfig.Scale2DTo3D;
                this._tmpP.z = -this.node.position.y * GlobalConfig.Scale2DTo3D;
                this._tmpP.y = 1;
                this.emit(EventTypes.EffectEvents.show2DEffect, { t: GlobalEnum.Effect2DType.BulletBoom, p: this._tmpP });
                break;
            //平民、僵尸
            case 1 << 5:
                this.emit(EventTypes.EnemyEvents.HitPeople, otherCollider.node.uuid, (isShoot) => {
                    this._isFinish = isShoot;
                });
                break;
            case 1 << 6:
                this.emit(EventTypes.RoleEvents.ByAtk, {
                    uuid: otherCollider.node.uuid, atk: this._atk, cb: (isShoot) => {
                        this._isFinish = isShoot;
                    }
                });
                break;
            default:
                break;
        }

    }

}

